package com.qkbb.admin.kuibu.qkbb.activity;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import com.qkbb.admin.kuibu.R;
import com.qkbb.admin.kuibu.adapter.MeetFriendAdapter;
import com.qkbb.admin.kuibu.qkbb.JavaBean.InVite;
import com.qkbb.admin.kuibu.qkbb.view.TitleBarView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class MeetFriend extends AppCompatActivity {
    private ListView listView;
    private TitleBarView titleBarView;
    private List<InVite> inViteList;
    private String result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meet_friend);
        listView= (ListView) findViewById(R.id.meet_friend_listview);
        titleBarView= (TitleBarView) findViewById(R.id.meet_friend_titlebar);
        titleBarView.setCenterTexiView("结识");
        titleBarView.settextColor(Color.WHITE);
        titleBarView.setLeftButton(R.mipmap.fanhui_04);
        titleBarView.setLeftButtonOnclick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Intent intent=getIntent();
        result=intent.getStringExtra("result");
        inViteList=new ArrayList<InVite>();
        if (result!=null){
            Log.e("555", result);
            InviteJson(result);
        }
        MeetFriendAdapter adapter=new MeetFriendAdapter(inViteList,getApplication());
        listView.setAdapter(adapter);


    }
    private void InviteJson(String result) {
        try {
            JSONObject jsonObject=new JSONObject(result);
            JSONObject jsonObject1=jsonObject.getJSONObject("data");
            JSONArray jsonArray=jsonObject1.getJSONArray("invitations");
            for(int i=0;i<jsonArray.length();i++){
                JSONObject jsonObject2=jsonArray.getJSONObject(i);
                InVite inVite=new InVite();
                inVite.setNickname(jsonObject2.getString("nickname"));
                inVite.setPhoto(jsonObject2.getString("photo"));
                inVite.setAddstatus(jsonObject2.getString("addstatus"));
                inVite.setFriendid(jsonObject2.getString("friendid"));
                inVite.setInvitationid(jsonObject2.getString("invitationid"));
                inVite.setReason(jsonObject2.getString("reason"));
                inVite.setSignature(jsonObject2.getString("signature"));
                inViteList.add(inVite);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
